from django.db import models
from django.conf import settings


class Notification(models.Model):
    """
    用户通知
    """
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='notifications')
    title = models.CharField(max_length=200)
    body = models.TextField(blank=True, default='')
    type = models.CharField(max_length=50, blank=True, default='general')
    read = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-created_at']

    def __str__(self):
        return f'{self.title} ({"read" if self.read else "unread"})'